<html>
<head><meta charset="utf-8"><title>Emacs LSP - problem with layout · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html">Emacs LSP - problem with layout</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="198191482"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198191482" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198191482">(May 20 2020 at 12:36)</a>:</h4>
<p>Hi, I have been afflicted by some strange layout problem with Emacs and LSP. I cant explain with words, so I'll post two animation files. I'm using Sway under Wayland (in case it is relevant)</p>



<a name="198191556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198191556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198191556">(May 20 2020 at 12:37)</a>:</h4>
<p>Basically when LSP is trying to open the <code>rustfmt</code> error log window, the Emacs buffer is swapped under my nose and the <code>rustfmt</code> buffer log is put in foreground</p>



<a name="198191574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198191574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198191574">(May 20 2020 at 12:37)</a>:</h4>
<p>Example where is does <em>not</em> happen</p>



<a name="198191586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198191586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198191586">(May 20 2020 at 12:37)</a>:</h4>
<p><a href="/user_uploads/4715/tuK8d5-hCCoUHNtiHJiX73QJ/recording1.webm">recording1.webm</a></p>



<a name="198191666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198191666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198191666">(May 20 2020 at 12:38)</a>:</h4>
<p>(The source buffer is not completely covered and on the right we see the rustfmt buffer)</p>



<a name="198191678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198191678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198191678">(May 20 2020 at 12:38)</a>:</h4>
<p><a href="/user_uploads/4715/dOLdtLGJ31gGEQ5YpZiIVJnz/recording2.webm">recording2.webm</a></p>



<a name="198191739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198191739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198191739">(May 20 2020 at 12:39)</a>:</h4>
<p>(Here I shrink slightly the CLI window and the <code>rustfmt</code> emacs buffer with the source code is put in background, I have to switch back to fix the code)</p>



<a name="198191843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198191843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198191843">(May 20 2020 at 12:40)</a>:</h4>
<p>I can't even search on github what I can do to avoid this behaviour, I'd like to disable all the accessory buffers that popup and are distracting</p>



<a name="198191875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198191875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198191875">(May 20 2020 at 12:40)</a>:</h4>
<p>Sorry for being vague <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span>  and thanks for any suggestion</p>



<a name="198194006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198194006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198194006">(May 20 2020 at 12:59)</a>:</h4>
<p>I don't think that error buffer comes from LSP, rather from the separate Emacs rustfmt integration</p>



<a name="198194031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198194031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198194031">(May 20 2020 at 12:59)</a>:</h4>
<p>LSP can format the file for you, but it won't open an error buffer if it fails</p>



<a name="198194178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198194178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198194178">(May 20 2020 at 13:00)</a>:</h4>
<p>so I would recommend using the LSP formatter instead (that's <code>lsp-format-buffer</code>)</p>



<a name="198194517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198194517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198194517">(May 20 2020 at 13:03)</a>:</h4>
<p>ahh thanks, I will definitively try that and locate the offending package</p>



<a name="198456463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198456463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198456463">(May 22 2020 at 15:42)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> ok fixed that issue and got rid of some redundant configs. Now, I have another question about <code>rustfmt</code>.  Does lsp-rust currently have a  rustfmt-on-save hook? I think I only see a <code>rust-build-on-save</code> but nothing else configurable on save</p>



<a name="198456775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198456775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198456775">(May 22 2020 at 15:45)</a>:</h4>
<p>I don't think it has built-in support, but I guess something like</p>
<div class="codehilite"><pre><span></span><code><span class="p">(</span><span class="nv">add-hook</span> <span class="ss">&#39;before-save-hook</span> <span class="p">(</span><span class="nb">lambda</span> <span class="p">()</span> <span class="p">(</span><span class="nb">when</span> <span class="p">(</span><span class="nf">eq</span> <span class="ss">&#39;rust-mode</span> <span class="nv">major-mode</span><span class="p">)</span>
                                           <span class="p">(</span><span class="nv">lsp-format-buffer</span><span class="p">))))</span>
</code></pre></div>


<p>should work</p>



<a name="198457750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198457750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198457750">(May 22 2020 at 15:52)</a>:</h4>
<p>nice, I will try it - thanks!</p>



<a name="198527542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Emacs%20LSP%20-%20problem%20with%20layout/near/198527542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Emacs.20LSP.20-.20problem.20with.20layout.html#198527542">(May 23 2020 at 09:42)</a>:</h4>
<p>works great! I would like to submit for evaluation a small PR to the documentation, if you don't mind. I think that snippet is of great value :-)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>